package com.banciyuan.bcywebview.utils.regex;

import android.text.util.Linkify;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by squall on 2015/10/14.
 */
public class MatchFilterImpl implements Linkify.MatchFilter {

    private static List<Pattern> slist = new ArrayList<>();

    static {
        slist.add(Pattern.compile("^https?://bcy\\.net/coser/detail/\\d+/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/illust/detail/\\d+/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/novel/detail/\\d+/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/daily/detail/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/group/list/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/group/detail/\\d+/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/novel/set/detail/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/huodong/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/u/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/circle/index/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/tags/name/\\S+"));
        slist.add(Pattern.compile("^https?://bcy\\.net/special/detail/\\d+$"));
        slist.add(Pattern.compile("^https?://bcy\\.net/zhipin/detail/\\d+$"));
    }

    @Override
    public boolean acceptMatch(CharSequence charSequence, int i, int i1) {
        for (Pattern s : slist) {
            Matcher matcher = s.matcher(charSequence.toString());
            if (matcher.matches()) {
                return true;
            }
        }
        return false;
    }
}
